export default {
  data() {
    return {
      show: false,
      price: '', //输入金额
      inputPass: false, //输入密码
      Password: '', //input输入的值
      agenPassword: '', //input输入的值

      show: false, //弹窗

      forget: false, //忘记密码弹窗

      phone: false, //验证手机号

      seconds: 60,
      tips: '重新发送',
      carInfo: {
        bank_num: ''
      },
      balance: 0,
      cardList: [],
      color: '2rpx solid #EEEEEE',
      pageLoading: false,
      mobile: '',
      userId: '',
    }
  },
  created() {
    this.mobile = uni.getStorageSync('Ztc_C_USER_INFO').mobile
    this.userId = uni.getStorageSync('Ztc_C_USER_INFO').id
  },
  onShow() {
    this.getBankcardList()
    this.GetUserIdentityInfo()
  },
  methods: {
    filterNum(val){
      let num = 0
      num = val
      return num.substr(val.length-4)
    },
    filterTel(tel) {
      let reg = /^(\d{3})\d*(\d{4})$/
      return tel.replace(reg, '$1****$2')
    },
    //申请提现
    async withdrawal() {
      console.log(this.carInfo.id)
      try {
        let data = {
          'platform': 0,
          'accountId': this.userId, //申请账户id
          'applyWithdrawMoney': this.price, //申请提现金额
          'payPassword': this.Password,
          'bankid': this.carInfo.id
        }
        const res = await this.$api.fundModule.applyWithdraw(data)
        console.log(res)
        if (res.code === 200) {
          this.$refs.uToast.show({
            title: '提现金额会在3个工作日内到账',
            type: 'success',
            back: true
          })
        }
      } catch (e) {

      }
    },
    //查看余额
    async getUserMoneyInfo() {
      try {
        const res = await this.$api.me.getUserMoneyInfo()
        this.balance = res.data.balance
        this.IsExistPayPwd()
      } catch (e) {
        this.pageLoading = false
      }
    },
    //选择银行卡
    choose(list) {
      // console.log(list)
      this.carInfo = list
      // this.carInfo.bank_num = list.bank_num.substr(-4)
      this.show = false
    },
    //银行卡
    async getBankcardList() {
      try {
        let data = {
          'pageIndex': 1,
          'pageSize': 10
        }
        const res = await this.$api.fundModule.getBankcardList(data)
        this.getUserMoneyInfo()
        this.cardList = res.data.list
        this.carInfo = res.data.list[0]

      } catch (e) {
        this.pageLoading = false
      }
    },
    //是否设置支付密码
    async IsExistPayPwd() {
      try {
        const res = await this.$api.user.IsExistPayPwd()
        this.isSetPayPsd = res.data
        this.pageLoading = true
      } catch (e) {
        this.pageLoading = false
        console.log(e)
        //TODO handle the exception
      }
    },
    //验证码
    async GetUserIdentityInfo() {
      try {
        const res = await this.$api.fundModule.GetUserIdentityInfo({})
        console.log(res)

      } catch (err) {}
    },
    //确认提现
    cofWithdrawal() {
      if (this.price === '') {
        uni.showToast({
          title: '请输入提现金额',
          icon: 'none'
        })
        this.color = '2rpx solid #EA0000'
        return false
      } else if (this.price > this.balance) {
        uni.showToast({
          title: '提现金额不能大于余额',
          icon: 'none'
        })
        this.color = '2rpx solid #EA0000'
        return false
      } else if (this.price === '0') {
        uni.showToast({
          title: '提现金额不能为0',
          icon: 'none'
        })
        this.color = '2rpx solid #EA0000'
        return false
      }
      if (this.isSetPayPsd) {
        this.inputPass = true
      } else {
        uni.showToast({
          title: '请先设置支付密码',
          icon: 'none'
        })
        setTimeout(() => {
          this.setPwd()
          /* uni.navigateTo({
						url: '/pages_userModule/setPassword/setPsd'
					}) */
        }, 1200)
      }
    },
    // ?caridxix=withdrawal

    //设置密码
    setPwd() {
      uni.navigateTo({
        url: '/pages_fundModule/paymentPassword/paymentPassword'
      })
    },
    start() {
      this.$u.toast('倒计时开始')
    },
    codeChange(text) {
      this.tips = text
    },

    //验证码结束
    end() {

    },
    //验证码输入完
    finishPhone() {
      console.log(1)
    },
    changePhone() {

    },
    //提现记录
    record() {
      uni.navigateTo({
        url: '/pages_fundModule/record/record'
      })
    },

    //下一步
    next() {
      this.phone = true
      this.forget = false
      setTimeout(() => {
        this.$refs.uCode.start()
      }, 300)
    },
    //forget忘记密码
    forgetPwd() {
      this.forget = true
      this.inputPass = false
    },
    changePrice(e) {
      this.price = e.detail.value
    },

    // 全部提现
    allPrice() {
      this.price = this.balance
    },
    //确认提现
    comfig() {

    },
    //添加新卡
    addCard() {
      uni.navigateTo({
        url: '/pages_fundModule/addBankCard/addBankCard?type=add'
      })
    },
    //实时监控 请输入密码input输入的值
    changeInputf(e) {
      // console.log(this.Password)
      // console.log('内容改变，当前值为：' + e)
    },
    //输入支付密码结束
    finish(e) {
      this.Password = e
      console.log('输入结束，当前值为：' + e)
    }
  }
}
